package edu.thu.studio.ormdesigner.editor.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.PlatformUI;

import edu.thu.studio.ormdesigner.editor.dialog.TableDialog;
import edu.thu.studio.ormdesigner.editor.figure.TableFigure;
import edu.thu.studio.ormdesigner.model.diagram.node.TableNode;
import edu.thu.studio.ormdesigner.model.orm.table.Table;
import edu.thu.studio.ormdesigner.outline.command.UpdateTableCommand;

public class TableNodeEditPart extends NodeEditPart {

	@Override
	protected IFigure createFigure() {
		TableFigure figure = new TableFigure();
		return figure;
	}

	@Override
	public void performRequestOpen() {
		Table table = ((TableNode) this.getModel()).getRefTable();
		TableDialog dialog = new TableDialog(PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getShell(), this.getViewer(), table);
		if (dialog.open() == IDialogConstants.OK_ID) {
			UpdateTableCommand command = new UpdateTableCommand(table);
			this.executeCommand(command);
		}
	}

}
